<?php
class db {

	protected $id;
	protected $data;
	protected $db;
	protected $change = false;
		
	//构造函数来查询数据	
	function __constract ($id) {
		$this->db = mysql_connect(127.0.0.1);
		$res = $this->db->query('select id,name from aa');
		$this->data = $res->fetch_assoc();
		$this->id = $id
	}

	//析构函数来修改，插入，删除数据
	function __distruct () {
		//通过change来决定执行什么操作
		if($this->change) {
			foreach ($this->data as $k => $v) {
				$fields[] = "$k = {$v}";
			}
			$this->db->query("update user set ".implode(',',$fields)"where id = {$this->id} limit 1");
		}
	
	}



}
